package com.my.internetplus.controller;

import com.my.internetplus.model.Order;
import com.my.internetplus.result.BaseResult;
import com.my.internetplus.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController {
    @Resource
    private OrderService orderService;

    //获取订单列表
    @RequestMapping("getordersList")
    public BaseResult<List<Order>> getordersList(int userid){

        List<Order> getorders = orderService.getordersList(userid);

        if (getorders!=null){
            return BaseResult.success(getorders);
        }else {
            return BaseResult.fall(400,"服务器内部出错");
        }
    }

    //获取订单详情
     @RequestMapping("getOrderDetail")
    public BaseResult<Map> getOrderDetail(long detailid){
         System.out.println("aaaaaaaaaa");
        return BaseResult.success(orderService.getOrderDetail(detailid));

     }

     //修改订单状态
     @RequestMapping("setCnform")
    public void setCnform(long orderid){
        orderService.setCnform(orderid);
     }

     @RequestMapping("delectOrder")
    public void delectOrder(long orderid){
        orderService.delectOrder(orderid);
     }

     @RequestMapping("addorder")
    public void addorder(String cart,int selectedAdd,String sum,String openid){
         orderService.addorder(Arrays.asList(cart.replace("\"", "").split(",")), selectedAdd, sum, openid);
     }
}
